{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content"> 
				<div class="row row-lg"> 
					<div class="col-sm-12"> 
						<div class="row" id="searchGroup">
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">关键字</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="keyword" placeholder="关键字" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">称呼</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="simple_name" placeholder="称呼" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">性别</button>
									</div>
									<select class="form-control" id="gender">
										<option value="">请选择</option>
										<option value="1">男</option>
										<option value="2">女</option>
									</select>
								</div>
							</div>

							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">所在地城市</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="city" placeholder="所在地城市" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">婚姻状况</button>
									</div>
									<select class="form-control" id="marital_status">
										<option value="">请选择</option>
										<option value="1">未婚</option>
										<option value="2">离异</option>
										<option value="3">丧偶</option>
									</select>
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">年薪</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="income" placeholder="月收入" />
								</div>
							</div>

							<!-- search end -->
							<div class="col-sm-1">
								<button type="button" class="btn btn-success " onclick="CodeGoods.search()" id="">
									<i class="fa fa-search"></i>&nbsp;搜索
								</button>
							</div>

							<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">

								<button type="button" id="import" class="btn btn-primary button-margin" >
									导入
								</button>
								<a type="button" class="btn btn-primary button-margin" target="_blank" href="__PUBLIC__/static/excel/佳人导入模板.xls">
									下载导入模板
								</a>
								<a type="button" class="btn btn-success button-margin" target="_blank" href="__PUBLIC__/static/excel/佳人导入模板简化版.xls">
									下载简化版模板
								</a>
							  <a type="button" class="btn btn-success button-margin" target="_blank" href="export">
									导出
								</a>


						</div>
							<button type="button" id="add" class="btn btn-primary button-margin" onclick="CodeGoods.add()">
								<i class="fa fa-plus"></i>&nbsp;添加
							</button>

						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>

			</div>
		</div>
	</div>
</div>
	<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};
	layui.use(['form', 'upload','layer'], function () {
		var upload = layui.upload;
		var layer = layui.layer
		var uploadInst = upload.render({
			elem: '#import' //绑定元素
			,accept: 'file'
			,exts:'xls'
			,url: Feng.ctxPath + "/ZhAuthentication/import" //上传接口
			,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
				layer.load(); //上传loading
			}
			,done: function(data){
				layer.closeAll('loading'); //关闭loading
				//上传完毕回调
				if ('00' === data.status) {
					if(data.exist.length == 0) {
						Feng.success(data.msg, 5000);
					} else {
						Feng.success(data.msg+','+data.exist.join(',')+'是现有用户，对应的资料导入失败！', 5000);
					}
					CodeGoods.table.refresh();
				} else {
					Feng.error(data.msg + "！", 1000);
				}
			}
			,error: function(data){
				console.log(data);
				layer.closeAll('loading'); //关闭loading
				//请求异常回调
			}
		});
	});
	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
 			{title: '编号', field: 'authentication_id', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '头像', field: 'head_portrait', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.head_portraitFormatter},
 			{title: '称呼', field: 'simple_name', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '性别', field: 'gender', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.genderFormatter},
 			{title: '年龄', field: 'age', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '所在地城市', field: 'city', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '手机号', field: 'contact', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '红娘名称', field: 'name', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.statusFormatter},
            {title: '开关', field: 'is_frame', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.is_frameFormatter},
 			{title: '操作', field: '', visible: true, align: 'center', valign: 'middle',formatter: 'CodeGoods.buttonFormatter'},
 		];
 	};

	CodeGoods.buttonFormatter = function(value,row,index) {
		if(row.authentication_id){
			var str= '';
            {if condition="in_array('backend/ZhAuthentication/update',session('backend.nodes')) || session('backend.role_id') eq 1"}
            str += '<button type="button" class="btn btn-success btn-xs" title="修改"  onclick="CodeGoods.update('+row.authentication_id+')"><i class="fa fa-pencil"></i>&nbsp;修改</button>&nbsp;';
            {/if}
			{if condition="in_array('backend/ZhAuthentication/view',session('backend.nodes')) || session('backend.role_id') eq 1"}
			str += '<button type="button" class="btn btn-info btn-xs" title="查看详情"  onclick="CodeGoods.view('+row.authentication_id+')"><i class="fa fa-eye"></i>&nbsp;查看详情</button>&nbsp;';
			{/if}
            {if condition="in_array('backend/ZhAuthentication/delete',session('backend.nodes')) || session('backend.role_id') eq 1"}
            str += '<button type="button" class="btn btn-danger btn-xs" title="删除"  onclick="CodeGoods.delete('+row.authentication_id+')"><i class="fa fa-trash"></i>&nbsp;删除</button>&nbsp;';
            {/if}
			return str;
		}
	}

	CodeGoods.genderFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">男</span>';
				break;
				case '2':
					return '<span class="label label-warning">女</span>';
				break;
			}
		}
	}

    CodeGoods.statusFormatter = function(value,row,index) {
        if(value !== null){
            var value = value.toString();

            switch(value){
                case '0':
                    return '<span class="label label-info">待审核</span>';
                    break;
                case '1':
                    return '<span class="label label-success">通过</span>';
                    break;
                case '2':
                    return '<span class="label label-warning">已拒绝</span>';
                    break;
            }
        }
    }

    CodeGoods.updateis_frame = function(pk,value,field) {
        var ajax = new $ax(Feng.ctxPath + "/ZhAuthentication/updateExt", function (data) {
            if ('00' !== data.status) {
                Feng.error(data.msg);
                $("."+field+pk).prop("checked",!$("."+field+pk).prop("checked"));
            }
        });
        var val = $("."+field+pk).prop("checked") ? 1 : 0;
        ajax.set('authentication_id', pk);
        ajax.set('is_frame', val);
        ajax.start();
    }


    CodeGoods.is_frameFormatter = function(value,row,index) {
        if(value !== null){
            if(value == 1){
                return '<input class="mui-switch mui-switch-animbg status'+row.authentication_id+'" type="checkbox" onclick="CodeGoods.updateis_frame('+row.authentication_id+',0,\'status\')" checked>';
            }else{
                return '<input class="mui-switch mui-switch-animbg status'+row.authentication_id+'" type="checkbox" onclick="CodeGoods.updateis_frame('+row.authentication_id+',1,\'status\')">';
            }
        }
    }

    CodeGoods.head_portraitFormatter = function(value,row,index) {
        if(value){
            return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";
        }
    }



	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['offset'] = 0;
		queryData['keyword'] = $("#keyword").val();
		queryData['simple_name'] = $("#simple_name").val();
		queryData['gender'] = $("#gender").val();
		queryData['date_birth'] = $("#date_birth").val();
		queryData['city'] = $("#city").val();
		queryData['marital_status'] = $("#marital_status").val();
		queryData['income'] = $("#income").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.view = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhAuthentication/view?authentication_id='+value});
			if(!IsPC()){layer.full(index)}
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.authentication_id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhAuthentication/view?authentication_id='+idx});
				this.layerIndex = index;
				if(!IsPC()){layer.full(index)}
			}
		}
	}

    CodeGoods.update = function (value) {
        if(value){
            var index = layer.open({type: 2,title: '修改',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhAuthentication/update?authentication_id='+value});
            if(!IsPC()){layer.full(index)}
        }else{
            if (this.check()) {
                var idx = '';
                $.each(CodeGoods.seItem, function() {
                    idx += ',' + this.authentication_id;
                });
                idx = idx.substr(1);
                if(idx.indexOf(",") !== -1){
                    Feng.info("请选择单条数据！");
                    return false;
                }
                var index = layer.open({type: 2,title: '修改',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhAuthentication/update?authentication_id='+idx});
                this.layerIndex = index;
                if(!IsPC()){layer.full(index)}
            }
        }
    }

    CodeGoods.delete = function (value) {
        if(value){
            Feng.confirm("是否删除选中项？", function () {
                var ajax = new $ax(Feng.ctxPath + "/ZhAuthentication/delete", function (data) {
                    if ('00' === data.status) {
                        Feng.success(data.msg);
                        CodeGoods.table.refresh();
                    } else {
                        Feng.error(data.msg);
                    }
                });
                ajax.set('authentication_id', value);
                ajax.start();
            });
        }else{
            if (this.check()) {
                var idx = '';
                $.each(CodeGoods.seItem, function() {
                    idx += ',' + this.id;
                });
                idx = idx.substr(1);
                Feng.confirm("是否删除选中项？", function () {
                    var ajax = new $ax(Feng.ctxPath + "/ZhAuthentication/delete", function (data) {
                        if ('00' === data.status) {
                            Feng.success(data.msg,1000);
                            CodeGoods.table.refresh();
                        } else {
                            Feng.error(data.msg,1000);
                        }
                    });
                    ajax.set('authentication_id', idx);
                    ajax.start();
                });
            }
        }
    }

	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/ZhAuthentication/index"+url,defaultColunms,20);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});

	CodeGoods.add = function (value) {
		var url = location.search;
		var index = layer.open({type: 2,title: '添加',area: ['800px', '500px'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhAuthentication/add'+url});
		this.layerIndex = index;
		if(!IsPC()){layer.full(index)}
	}
</script>
{/block}